package com.example.statistics.ui.inventory

import android.os.Bundle
import com.example.statistics.R
import com.example.statistics.bean.InventoryBean
import com.example.statistics.common.BaseLoadingListActivity
import com.example.statistics.ex.actionDialog
import com.example.statistics.ex.goTimeFormat
import com.example.statistics.net.UrlConfig
import com.example.statistics.utils.Constants
import com.example.statistics.utils.activityFinish
import com.example.statistics.utils.activityForResult
import com.jhj.slimadapter.SlimAdapter
import com.jhj.slimadapter.holder.ViewInjector


/**
 * 仓库库存
 */
class InventoryStockListActivity : BaseLoadingListActivity<InventoryBean>() {

    var action: String? = null


    override val title: String
        get() = "库存"
    override val url: String
        get() = UrlConfig.INVENTORY_PRODUCT_LIST
    override val itemLayoutRes: Int
        get() = R.layout.list_item_inventory_stock

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        action = intent.getStringExtra(Constants.ACTION)
        topBarRightImage {
            actionDialog(
                    "市场调货" to {
                        activityForResult<InventoryAddActivity>() {
                            refresh()
                        }
                    },
            )
        }
    }

    override fun itemViewConvert(adapter: SlimAdapter, injector: ViewInjector, bean: InventoryBean, position: Int) {
        injector.text(R.id.tv_title, bean.factoryNo + bean.productName)
                .text(R.id.tv_code, bean.containerNo + " | " + bean.contractNo)
                .text(R.id.tv_number, bean.inventoryNumber.toString() + "件 | ￥" + bean.unitPrice)
                .text(R.id.tv_date, " " + bean.date.goTimeFormat())
                .clicked {
                    if (!action.isNullOrBlank()) {
                        activityFinish(Constants.DATA to bean)
                    }
                }
    }
}